(ns ura.ui
  (:require
   [reagent.core :as r]
   [reagent.dom :as rd]
   [reagent.ratom :as ra]
   [stylefy.core :as sty]
   [stylefy.reagent :as stylefy-reagent]
   [ajax.core :refer [GET POST DELETE]]
   [ura.common :as uc :refer [log spy]]
   [ura.style :as style :refer [attr]]
   [ura.popup :refer [showPopup]]

   [re-com.core :as rc :refer [at]]
   ))


(defn my-toolbar [atr & nodes]
    (into
     [:div (merge atr (attr :flex :m=10px:5px :jc-b))]
     nodes
    )
  )

(defn my-label ""
  [& args]

  (let [
        [p1 & pleft] args
        attrs (if (map? p1) p1 {})
        children (if (map? p1) pleft args)
        ]
    (log ["label attrs1: " attrs ])
    (into
     [:span (merge attrs (attr :align-self=center
                               :text-wrap-mode=nowrap
                               :font-weight=600
                               :pl=10px
                  ) ) ]
     
     children )
    )
  )

(defn MyInput [atr & subItems]
  (let [value (:model atr)
        type (:type atr)
        ]
    (fn []
      (cond
        (= type "textarea")
        [rc/input-textarea {:model value
                            :on-change #(reset! value %)
                            }]
        :default
        [rc/input-text {:model value
                        :on-change #(reset! value %)
                        }]
        )
      )))


(defn MyFormField [atr & nodes]
  (let [required (get atr :required false)
        label (get  atr :label "-")
        ]
    (fn []
    [:div
     [:div (attr :flex :p=5 :m=10)
      [:span (attr :w=100 :color=black :font-weidht-600 :align-self=center :text-align=right)
       (if required [:span (attr :color=red :p=3) "*"])
       label "："
       ]
      (into [:div (attr :w=100% ) ] nodes)
      ]
     ]
    ))
  )
